﻿using UnityEngine;
using System.Collections;
using ProtoBuf.Message;

namespace Room
{
    public class PlayerAIStateDefend : PlayerAIStateBase
    {
        //float timeLast = 60f;
        //float currentTime;
        GameObject def;
        protected override void OnEnter()
        {
            controller.owner.PlayAnim(AniName.IDLE_FIGHT);
            //this.currentTime = 0f;
            //timeLast = Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.FieldPVPCountDown + Dict.DictDataManager.Instance.tableGameConfigureDao.currentData.FieldPVPKeep;

            if(def!=null)
            {
                GameObjectPoolManager.Instance.Unspawn(def);
            }

            def = GameObjectPoolManager.Instance.Spawn(RoomField.particleDefAb, CommonMethod.GetAssetNameFromAssetBundleName(RoomField.particleDefAb));
            def.transform.SetParent(controller.owner.transform);
            def.transform.localScale = Vector3.one;
            def.transform.localPosition = Vector3.zero+new Vector3(0,2,0);
            //def.transform.SetParent(controller.owner.transform.parent);
            def.SetActive(true);

            //如果是自己
            //if(long.Parse(controller.owner.name) == StaticData.playerData.playerId)
            //{
            //    if(RoomManager.curSceneType == SceneType.FIELD)
            //    {
            //        CSSidePveFightEnd end = new CSSidePveFightEnd();
            //        NetAPI.SendSocket(OpDefine.CSSidePveFightEnd, end);
            //    }
            //}
            
        }

        //protected override void OnTick()
        //{
        //    currentTime += Time.deltaTime;
        //    if(currentTime >= timeLast)
        //    {
        //        var ctrl = controller.owner.ai as RCAIActor;
        //        ctrl.SwitchState(PlayerAIState.Normal);
        //    }
        //}

        protected override void OnLeave()
        {
            Debug.Log("[DEBUG] exit state:" + PlayerAIState.Defend);
            controller.owner.PlayAnim(AniName.STAND);
            GameObjectPoolManager.Instance.Unspawn(def);   
        }
    }
}